package View.Index;

import View.BreakRule.DelBreakRule;
import View.BreakRule.QueryBreakRule;
import View.BreakRule.UpdateBreakRule;
import View.BreakRule.addBreakRule;
import View.Dorm.AddDorm;
import View.Dorm.DelDorm;
import View.Dorm.QueryDorm;
import View.Dorm.UpdateDorm;
import View.Message.HistoryMsg;
import View.Message.NewMsg;
import View.Repair.DelRepair;
import View.Repair.QueryRepair;
import View.Repair.UpdateRepair;
import View.Student.AddStudent;
import View.Student.DelStudent;
import View.Student.QueryStudent;
import View.Student.UpdateStudent;
import View.User.AddUser;
import View.User.DeleteUser;
import View.User.QueryUser;
import View.User.UpdateUser;
import View.apply.ChangeDormapp;
import View.apply.OutApplyPage;
import View.apply.RepairApply;
import View.dianming.dianming;
import domain.User;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Index_admin extends JFrame {

    public Index_admin(User user){
        init();
        componentInit(user);
    }


    public void init(){
        this.setTitle("主页");
        this.setSize(632,442);
        this.setResizable(true);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLayout(null);
    }


    public void componentInit(User user){
        //------------------JLabel--------------------
        JLabel label1= new JLabel();
        label1.setText(user.getUsername()+"欢迎来到宿舍管理系统,你现在的身份是"+user.getType()+",请在菜单栏选择操作");
        label1.setBounds(100,49,393,161);
        JLabel label2= new JLabel();
/*        label2.setText("欢迎回来张三,你现在的身份是user");
        label2.setBounds(382,315,198,82);*/

        //Menu
        JMenuBar menuBar = new JMenuBar();
        JMenu menu = new JMenu("用户管理");
        JMenuItem item = new JMenuItem("添加用户");
        JMenuItem item1 = new JMenuItem("修改用户");
        JMenuItem item2 = new JMenuItem("删除用户");
        JMenuItem item3 = new JMenuItem("查找用户");
        menu.add(item);
        menu.add(item1);
        menu.add(item2);
        menu.add(item3);

        JMenu menu1 = new JMenu("学生管理");
        JMenuItem item4 = new JMenuItem("添加学生");
        JMenuItem item5 = new JMenuItem("查找学生");
        JMenuItem item6 = new JMenuItem("修改学生");
        JMenuItem item7 = new JMenuItem("删除学生");
        menu1.add(item4);
        menu1.add(item5);
        menu1.add(item6);
        menu1.add(item7);

        JMenu menu2 = new JMenu("宿舍管理");
        JMenuItem item8 = new JMenuItem("添加宿舍");
        JMenuItem item9 = new JMenuItem("查找宿舍");
        JMenuItem item10 = new JMenuItem("修改宿舍");
        JMenuItem item11 = new JMenuItem("删除宿舍");
        menu2.add(item8);
        menu2.add(item9);
        menu2.add(item10);
        menu2.add(item11);


        JMenu menu3 = new JMenu("报修管理");
        JMenuItem item13 = new JMenuItem("查找报修");
        JMenuItem item14 = new JMenuItem("修改报修");
        JMenuItem item15 = new JMenuItem("删除报修");
        menu3.add(item13);
        menu3.add(item14);
        menu3.add(item15);

        JMenu menu4 = new JMenu("申请处理");
        JMenuItem item16 = new JMenuItem("外出申请");
        JMenuItem item17 = new JMenuItem("宿舍更换申请");
        JMenuItem item20 = new JMenuItem("报修申请");
        menu4.add(item16);
        menu4.add(item17);
        menu4.add(item20);

        JMenu menu5 = new JMenu("消息");
        JMenuItem item18 = new JMenuItem("查看未读消息");
        JMenuItem item19 = new JMenuItem("查看历史消息");
        menu5.add(item18);
        menu5.add(item19);

        JMenu menu6 = new JMenu("宿舍点名");
        JMenuItem item21 = new JMenuItem("点击查看点名详情");
        menu6.add(item21);

        JMenu menu7 = new JMenu("学生违纪");
        JMenuItem item22 = new JMenuItem("添加违纪记录");
        JMenuItem item23 = new JMenuItem("查看违纪记录");
        JMenuItem item24 = new JMenuItem("撤销违纪记录");
        JMenuItem item25 = new JMenuItem("修改违纪记录");
        menu7.add(item22);
        menu7.add(item23);
        menu7.add(item24);
        menu7.add(item25);

        menuBar.add(menu);
        menuBar.add(menu1);
        menuBar.add(menu2);
        menuBar.add(menu3);
        menuBar.add(menu4);
        menuBar.add(menu5);
        menuBar.add(menu6);
        menuBar.add(menu7);

        this.add(label1);
        this.add(label2);
        this.setJMenuBar(menuBar);

        item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new AddUser(user).setVisible(true);
                dispose();
            }
        });

        item1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new UpdateUser(user).setVisible(true);
                dispose();
            }
        });

        item2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new DeleteUser(user).setVisible(true);
            }
        });

        item3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new QueryUser(user).setVisible(true);
            }
        });

        item4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new AddStudent(user).setVisible(true);
            }
        });

        item5.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new QueryStudent(user).setVisible(true);
            }
        });


        item6.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new UpdateStudent(user).setVisible(true);
            }
        });

        item7.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new DelStudent(user).setVisible(true);
            }
        });

        item8.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new AddDorm(user).setVisible(true);
            }
        });

        item9.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new QueryDorm(user).setVisible(true);
            }
        });

        item10.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new UpdateDorm(user).setVisible(true);
            }
        });

        item11.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new DelDorm(user).setVisible(true);
            }
        });

        item13.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new QueryRepair(user).setVisible(true);
            }
        });

        item14.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new UpdateRepair(user).setVisible(true);
            }
        });

        item15.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new DelRepair(user).setVisible(true);
            }
        });

        item16.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new OutApplyPage(user).setVisible(true);
            }
        });

        item17.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new ChangeDormapp(user).setVisible(true);
            }
        });

        item18.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new NewMsg(user).setVisible(true);
            }
        });

        item19.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new HistoryMsg(user).setVisible(true);
            }
        });

        item20.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new RepairApply(user).setVisible(true);
            }
        });

        item21.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new dianming(user).setVisible(true);
            }
        });

        item22.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new addBreakRule(user).setVisible(true);
            }
        });

        item23.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new QueryBreakRule(user).setVisible(true);
            }
        });

        item24.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new DelBreakRule(user).setVisible(true);
            }
        });

        item25.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new UpdateBreakRule(user).setVisible(true);
            }
        });
    }

}
